import matplotlib.pyplot as plt
import numpy as np


# draw the picture
def draw(baseball, javelin, longjump, polevault):

    plt.figure()

    plot1, = plt.plot(baseball[0], baseball[1],
                      'co-', linewidth=2.0, markersize=10.0)
    plot2, = plt.plot(javelin[0], javelin[1],
                      'bx-', linewidth=2.0, markersize=10.0)
    plot3, = plt.plot(longjump[0], longjump[1],
                      'rh-', linewidth=2.0, markersize=10.0)
    plot4, = plt.plot(polevault[0], polevault[1],
                      'k^-', linewidth=2.0, markersize=10.0)

    # set X axis
    plt.xlim([0.5, 1.0])
    plt.xticks(np.linspace(0.3, 1.0, 8))
    plt.xlabel("Recall", fontsize="x-large")

    # set Y axis
    plt.ylim([0, 1.0])
    plt.yticks(np.linspace(0, 1.0, 11))
    plt.ylabel("Precision", fontsize="x-large")

    # set figure information
    plt.title("PR Curve", fontsize="x-large")
    plt.legend([plot1, plot2, plot3, plot4], ("baseball", "javelin",
               "longjump", "polevault"), loc="lower left", numpoints=1)
    plt.grid(True)

    # draw the chart
    plt.show()

def f1(precision, recall):
    f1 = 2 * precision * recall / (precision + recall)
    return f1


# main function
def main():
    baseball = [(0.778, 0.722),
                (0.243, 0.630)]

    # Curve two
    javelin = [(0.842, 0.799),
               (0.696, 0.857)]

    # Curve three
    longjump = [(0.813, 0.813),
                (0.375, 0.680)]

    # Curve four
    polevault = [(0.913, 0.913),
                    (0.661, 0.813)]

    # Call the draw function
    # draw(baseball, javelin, longjump, polevault)

    classList = [baseball, javelin, longjump, polevault]
    for classItem in classList:
        for recall, precision in zip(classItem[0], classItem[1]):
            f1score = f1(precision, recall)
            print(f1score)





# function entrance
if __name__ == "__main__":
    main()
